package com.haoshuang.zhouzhoubang.ui.vm

import androidx.lifecycle.rxLifeScope
import com.haoshuang.zhouzhoubang.base.request
import com.haoshuang.zhouzhoubang.config.URLConstants
import com.haoshuang.zhouzhoubang.model.bean.ExamQuestionBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ExaminationViewModel2 : BaseViewModel() {
val getData = StatefulMutableLiveData<Any>()
    fun getData(vararg params: Pair<String, Any?>) {
        rxLifeScope.launch {
            request<Any>("/api/Skill/pass_exam", *params,
                onStart = {
                    getData.value = StateData.Loading
                },
                onError = { code, msg ->
                    getData.value = StateData.Error(code, msg)
                }, onSuccess = {
                    getData.value = StateData.Success(it)
                })
        }
    }
    val getExamQuestionData = StatefulMutableLiveData<ExamQuestionBean>()
    /** 获取考试试题API请求 */
    fun getExamQuestion(vararg params: Pair<String,Any?>) {
        rxLifeScope.launch {
            rxLifeScope.launch {
                request<ExamQuestionBean>(
                    URLConstants.HuoQvKaoShiShiTi,*params,
                    onStart = {
                        getExamQuestionData.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        getExamQuestionData.value = StateData.Error(code, msg)
                    },
                    onSuccess = {
                        getExamQuestionData.value = StateData.Success(it)
                    })
            }
        }
    }

    val submitResultData = StatefulMutableLiveData<List<String>>()
    /** API请求 */
    fun submitResult(vararg params: Pair<String,Any?>) {
        rxLifeScope.launch {
            rxLifeScope.launch {
                request<List<String>>(URLConstants.TiJiaoDaTiJieGuo,*params,
                    onStart = {
                        submitResultData.value = StateData.Loading
                    },
                    onError = { code, msg ->
                        submitResultData.value = StateData.Error(code, msg)
                    },
                    onSuccess = {
                        submitResultData.value = StateData.Success(it)
                    })
            }
        }
    }
}